package hsintiao.com.xintiaoAPP.controller;


import hsintiao.com.xintiaoAPP.entity.Comment;
import hsintiao.com.xintiaoAPP.entity.Reply;
import hsintiao.com.xintiaoAPP.service.ArticleDetailsService;
import hsintiao.com.xintiaoAPP.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//文章详情页(文章内容，留言信息)
@RestController
@RequestMapping("/articleDetails")
@CrossOrigin
public class ArticleDetailsController {
    @Autowired
    private ArticleDetailsService articleDetailsService;


    /*
    * 获取某个文章下的留言信息
    * */
    @PostMapping("/getComment")
    @ResponseBody
    public AjaxResult getComment(@RequestBody Comment comment){
        System.out.println("id="+comment.getArticleId());
        return articleDetailsService.getComment(comment.getArticleId());
    }

    /*
    * 在某个文章下进行留言
    * */
    @PostMapping("/leaveMessage")
    @ResponseBody
    public AjaxResult leaveMessage(@RequestBody Comment comment){
        System.out.println("留言="+comment);
        AjaxResult ajaxResult = articleDetailsService.leaveMessage(comment);
        return ajaxResult;
    }

    /*
    * 对某个留言进行回复
    * */
    @PostMapping("/leaveReply")
    @ResponseBody
    public AjaxResult leaveReply(@RequestBody Reply reply){
        System.out.println("回复="+reply);
        AjaxResult ajaxResult = articleDetailsService.leaveReply(reply);
        return ajaxResult;
    }
}
